﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DinhMuc.Public;

namespace DinhMuc.DAL
{
    public class tblSanPhamDAL
    {
        clsConnect cn = new clsConnect();
        public DataTable bangSanPham()
        {
            return cn.LoadTableStore("sp_sanPham_select");
        }
        public void import(string sql, tblSanPhamPublic p)
        {
            int para = 10;
            string[] name = new string[para];
            object[] value = new object[para];
            name[0] = "@A";
            name[1] = "@B";
            name[2] = "@C";
            name[3] = "@D";
            name[4] = "@E";
            name[5] = "@F";
            name[6] = "@G";
            name[7] = "@H";
            name[8] = "@I";
            name[9] = "@J";
            value[0] = p.MaSP;
            value[1] = p.TenSP;
            value[2] = p.CauTruc;
            value[3] = p.QuyCach;
            value[4] = p.SlTonKho;
            value[5] = p.SlSanxuat;
            value[6] = p.SlPhanTram;
            value[7] = p.TrucInPKDBB;
            value[8] = p.NvMang_pvt;
            value[9] = p.NlHat_phuGia;
            cn.UpdateTable(sql, name, value, para);
        }
        public int ThemSP(tblSanPhamPublic p)
        {
            string sql = "sp_sanPham_insert";
            int para = 10;
            string[] name = new string[para];
            object[] value = new object[para];
            name[0] = "@maSP";
            name[1] = "@tenSp";
            name[2] = "@cauTruc";
            name[3] = "@quyCach";
            name[4] = "@slTonKho";
            name[5] = "@slSanXuat";
            name[6] = "@slPhanTram";
            name[7] = "@trucInPKDBB";
            name[8] = "@nlMang_pvt";
            name[9] = "@nlHat_phuGia";
            value[0] = p.MaSP;
            value[1] = p.TenSP;
            value[2] = p.CauTruc;
            value[3] = p.QuyCach;
            value[4] = p.SlTonKho;
            value[5] = p.SlSanxuat;
            value[6] = p.SlPhanTram;
            value[7] = p.TrucInPKDBB;
            value[8] = p.NvMang_pvt;
            value[9] = p.NlHat_phuGia;
            
            return cn.UpdateTableStore(sql, name, value, para);

        }
        
        public int suaSP(tblSanPhamPublic p)
        {
            int para = 10;
            string[] name = new string[para];
            object[] value = new object[para];
            name[0] = "@maSP";
            name[1] = "@tenSp";
            name[2] = "@cauTruc";
            name[3] = "@quyCach";
            name[4] = "@slTonKho";
            name[5] = "@slSanXuat";
            name[6] = "@slPhanTram";
            name[7] = "@trucInPKDBB";
            name[8] = "@nlMang_pvt";
            name[9] = "@nlHat_phuGia";
            value[0] = p.MaSP;
            value[1] = p.TenSP;
            value[2] = p.CauTruc;
            value[3] = p.QuyCach;
            value[4] = p.SlTonKho;
            value[5] = p.SlSanxuat;
            value[6] = p.SlPhanTram;
            value[7] = p.TrucInPKDBB;
            value[8] = p.NvMang_pvt;
            value[9] = p.NlHat_phuGia;
            return cn.UpdateTableStore("sp_sanPham_update", name, value, para);
        }
        public int xoaSP(string maSP)
        {
            int para = 1;
            string[] name = new string[para];
            object[] value = new object[para];
            name[0] = "@maSP";
            value[0] = maSP;
            return cn.UpdateTableStore("sp_sanPham_delete", name, value, para);
        }
    }
}
